﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.SQLite;

namespace DataHandler.Test {
    [TestClass]
    public class DataHandlerTestBase {


        private TestContext testContextInstance;
        protected SQLiteConnection con;

        protected DataHandlerTestUtil util; 

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize() {
            

            DataBaseProperties properties = DataBaseProperties.GetInstance();
            properties.SQLiteDatabaseFile = @"D:\Projekte\RpgSoundMixer2.0\DBTest\rpgsoundmixer_fk.db.sqlite";
            this.con = new SQLiteConnection(properties.ConnectionString);

            this.util = new DataHandlerTestUtil(this.con);

            SQLiteCommand cmd = this.util.createCommandAndOpenConnection(); 

            // Commands für das Vorbereiten der Datenbank
            StringBuilder sb = new StringBuilder();
            sb.Append("DELETE FROM SoundSuite;");
            sb.Append("DELETE FROM EffektGroup;");
            sb.Append("DELETE FROM Effekt;");
            sb.Append("DELETE FROM Track;");
            sb.Append("DELETE FROM trackInEffekt;");
            sb.Append("DELETE FROM trackInCategorie;");
            sb.Append("DELETE FROM category;");
            sb.Append("INSERT INTO SoundSuite (idSoundSuite, Name, Abenteuer) VALUES (\"a614bc64-44c1-46f2-84f8-d69e74c36290\", \"Luli\", \"a1\");");
            sb.AppendFormat("INSERT INTO SoundSuite (idSoundSuite, Name, Abenteuer) VALUES (\"{0}\", \"Luli2\", \"a2\");", Guid.Parse("573EC5C7-48BC-469A-A9AC-6D54CD9D2B28"));
            
            sb.AppendFormat("INSERT INTO effektGroup (ideffektGroup, name, key, SoundSuite) VALUES ('{0}', \"Luli\", \"k\", '');", Guid.Parse("1118ACD5-406E-4C0D-BC60-58E49F651E75"));
            sb.AppendFormat("INSERT INTO effektGroup (ideffektGroup, name, key, SoundSuite) VALUES ('{0}', \"Luli\", \"k\", '{1}');", Guid.Parse("18CA4270-6139-4134-A068-D5DD04B259D6"), Guid.Parse("46D15C5F-A430-49E6-B719-6528374C4C46"));
            //sb.AppendFormat("INSERT INTO effektGroup (ideffektGroup, name, key, SoundSuite) VALUES ('{0}', \"Luli\", \"k\", '{1}');", Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"), Guid.Parse("46D15C5F-A430-49E6-B719-6528374C4C46"));
            sb.AppendFormat("INSERT INTO effektGroup (ideffektGroup, name,  SoundSuite) VALUES ('{0}', \"Luli\",  '{1}');", Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"), Guid.Parse("46D15C5F-A430-49E6-B719-6528374C4C46"));

            sb.Append("INSERT INTO effektGroup (ideffektGroup, name, key, SoundSuite) VALUES (\"ea70a68d-4010-44e7-a4a0-cede4fdd4a42\", \"Luli\", \"k\", \"a614bc64-44c1-46f2-84f8-d69e74c36290\");");


            sb.Append("INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (\"2b5267b5-4f05-44aa-8128-e1a6ce043d88\", \"luli\", \"k\", 1, 2, \"ea70a68d-4010-44e7-a4a0-cede4fdd4a42\");");
            sb.AppendFormat("INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (\"{0}\", \"luli2\", \"k\", 1, 2, \"{1}\");", Guid.Parse("590FE806-3E28-4DBC-8F00-270577B435B7"), Guid.Parse("30EF661E-8F47-41F4-A5FD-1B7ADAD2C465"));

            sb.AppendFormat("INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (\"{0}\", \"luli1\", \"k\", 1, 2, \"{1}\");", Guid.Parse("43EC8273-4340-4D0D-8667-2180CF31B6C2"), Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"));
            sb.AppendFormat("INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (\"{0}\", \"luli2\", \"l\", 1, 2, \"{1}\");", Guid.Parse("A327302D-B3D6-43B2-8DEC-487DF96E9EDD"), Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"));
            //sb.AppendFormat("INSERT INTO effekt (ideffekt, effektName, key, effektArt, volume, effektGroup) VALUES (\"{0}\", \"luli3\", \"m\", 1, 2, \"{1}\");", Guid.Parse("9BAE9B08-8911-469D-9559-4C073D9E5D01"), Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"));
            sb.AppendFormat("INSERT INTO effekt (ideffekt, effektName,  effektArt, volume, effektGroup) VALUES (\"{0}\", \"luli3\",  1, 2, \"{1}\");", Guid.Parse("9BAE9B08-8911-469D-9559-4C073D9E5D01"), Guid.Parse("CD2C4D31-3B9C-401B-9461-D9C310B6AA18"));

            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track1');", Guid.Parse("16B8C063-5CC4-4537-8986-F6E144B78980"));
            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track2');", Guid.Parse("9F0C441A-73B6-421E-B607-1EDB98EECEE5"));
            sb.AppendFormat("INSERT INTO trackInEffekt (effektId, TrackId) VALUES (\"2b5267b5-4f05-44aa-8128-e1a6ce043d88\", '{0}'); ", Guid.Parse("16B8C063-5CC4-4537-8986-F6E144B78980"));
            sb.AppendFormat("INSERT INTO trackInEffekt (effektId, TrackId) VALUES (\"2b5267b5-4f05-44aa-8128-e1a6ce043d88\", '{0}'); ", Guid.Parse("9F0C441A-73B6-421E-B607-1EDB98EECEE5"));
            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track2');", Guid.Parse("2EC2E896-0667-4858-AF98-430FED6EC29F"));
            sb.AppendFormat("INSERT INTO trackInEffekt (effektId, TrackId) VALUES ('{1}', '{0}'); ", Guid.Parse("2EC2E896-0667-4858-AF98-430FED6EC29F"), Guid.Parse("999364F0-1D08-46DD-AB45-1393FAC21614"));
            sb.AppendFormat("INSERT INTO trackInEffekt (effektId, TrackId) VALUES ('{1}', '{0}'); ", Guid.Parse("590FE806-3E28-4DBC-8F00-270577B435B7"), Guid.Parse("85086128-D123-42E5-9A55-03A70490B3D3"));

            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track11');", Guid.Parse("16C1B6A5-83E3-4955-AC3B-CF3DFBA89565"));
            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track12');", Guid.Parse("0046FEBA-4FFB-414D-9BDA-50F274A5FBAA"));
            sb.AppendFormat(@"INSERT INTO track (idTrack) VALUES ('{0}');", Guid.Parse("2E30E38B-9E16-4863-9054-367B019FC860"));
            
            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track13');", Guid.Parse("3A5D019E-7299-4A8C-B2F1-5E169F2271EE"));
            sb.AppendFormat(@"INSERT INTO track (idTrack, path, Name) VALUES ('{0}', 'C:\temp', 'Track13');", Guid.Parse("90459A70-8A6C-4FC2-8300-ACF5932EA101"));
            sb.AppendFormat(@"INSERT INTO track (idTrack) VALUES ('{0}');", Guid.Parse("802C02CB-1156-423F-8ED2-7A704964C3DD"));

            sb.AppendFormat(@"INSERT INTO category (idCategory, Name) VALUES ('{0}', 'Kampf');", Guid.Parse("5B7A7BB4-A25E-4A72-9148-5D57213A5A5F"));
            sb.AppendFormat(@"INSERT INTO category (idCategory, Name) VALUES ('{0}', 'Normal');", Guid.Parse("5531EE43-4976-4015-A526-36A0AFA816A8"));
            sb.AppendFormat(@"INSERT INTO category (idCategory) VALUES ('{0}');", Guid.Parse("76645126-A9D0-409C-9B9D-762B1F6CAD2B"));

            sb.AppendFormat(@"INSERT INTO trackInCategorie (trackId,categoryId) VALUES ('{0}', '{1}');", 
                Guid.Parse("3A5D019E-7299-4A8C-B2F1-5E169F2271EE"), 
                Guid.Parse("5B7A7BB4-A25E-4A72-9148-5D57213A5A5F"));
            sb.AppendFormat(@"INSERT INTO trackInCategorie (trackId,categoryId) VALUES ('{0}', '{1}');",
                Guid.Parse("90459A70-8A6C-4FC2-8300-ACF5932EA101"), 
                Guid.Parse("5B7A7BB4-A25E-4A72-9148-5D57213A5A5F"));
            sb.AppendFormat(@"INSERT INTO trackInCategorie (trackId,categoryId) VALUES ('{0}', '{1}');",
               Guid.Parse("802C02CB-1156-423F-8ED2-7A704964C3DD"),
                Guid.Parse("5B7A7BB4-A25E-4A72-9148-5D57213A5A5F"));

            cmd.CommandText = sb.ToString();
            
            cmd.ExecuteNonQuery();
        }
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion       
    }
}
